import { getServiceInfo } from '@/static/js/servicePro.js'
export default {
  data() {
    return {
      serviceObj: {},
      serviceInfo: {},
      page: 1,
      shopStatus: 'noMore',
      serviceShopList: [],
    }
  },
  onLoad(e) {
    console.log(e.id);
    this.getServiceInfo(e.id)
  },
  methods: {
    //回到上一页
    goBack() {
      uni.navigateBack({
        delta: 1
      });
    },

    //请求服务商详情
    getServiceInfo(id) {
      getServiceInfo({
        id,
        page: this.page,
        pageSize: 10,
      }).then(res => {
        if (res.code == 1) {
          this.serviceObj = res.data
          this.serviceInfo = res.data.info
          let arr = []
          if (this.page == 1) {
            this.serviceShopList = []
          }
          let newList = res.data.serviceshoplist.data
          if (newList.length >= this.pageSize) {
            this.shopStatus = 'more'
          } else {
            this.shopStatus = 'noMore'
          }
          let arr1 = arr.concat(newList)
          arr1.forEach(val => {
            let obj = {
              id: val.id,
              name: val.name,
              pic: val.pic.split(','),
              price: val.price,
            }
            this.serviceShopList.push(obj)
          })
        }
      })
    },

    // 获取不同的服务商类型
    getServiceType(type) {
      const providers = {
        1: "官方服务商",
        2: "金牌服务商",
        3: "银牌服务商",
        4: "铜牌服务商",
        5: "普通服务商"
      };

      return providers[type];
    },
    telPhone(e) {
      console.log(e);
      uni.makePhoneCall({
        phoneNumber: e
      })
    },
  },

  //上拉触底
  onReachBottom() {
    if (this.shopStatus == 'noMore') return
    this.page++
    this.getServiceInfo()
  },
}